home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
eofbof
/
eofbof.frm
next >
Wrap
Text File
|
1995-05-02
|
11KB
|
348 lines
VERSION 2.00
Begin Form frmEOF_BOF
BackColor = &H00C0C0FF&
Caption = "EOF / BOF"
ClientHeight = 4440
ClientLeft = 1200
ClientTop = 1500
ClientWidth = 6345
Height = 4845
Icon = EOFBOF.FRX:0000
KeyPreview = -1 'True
Left = 1140
LinkTopic = "Form1"
ScaleHeight = 4440
ScaleWidth = 6345
Top = 1155
Width = 6465
Begin CommandButton cmdPrint
Caption = "P&rint List"
Height = 396
Left = 4800
TabIndex = 4
Top = 960
Width = 1260
End
Begin ListBox lstActions
FontBold = -1 'True
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
Height = 2175
Left = 240
TabIndex = 11
Top = 2040
Width = 5865
End
Begin CommandButton cmdMove
Caption = "Move&Last"
Height = 396
Index = 3
Left = 4800
TabIndex = 8
Top = 1440
Width = 1260
End
Begin CommandButton cmdMove
Caption = "Move&Next"
Height = 396
Index = 2
Left = 3240
TabIndex = 7
Top = 1440
Width = 1260
End
Begin CommandButton cmdMove
Caption = "Move&Prev"
Height = 396
Index = 1
Left = 1725
TabIndex = 6
Top = 1440
Width = 1260
End
Begin CommandButton cmdMove
Caption = "Move&First"
Height = 396
Index = 0
Left = 240
TabIndex = 5
Top = 1440
Width = 1260
End
Begin CommandButton cmdRefresh
Caption = "&Refresh"
Height = 396
Left = 3270
TabIndex = 3
Top = 960
Width = 1260
End
Begin CommandButton cmdDelete
Caption = "&Del Rec"
Height = 396
Left = 1725
TabIndex = 2
Top = 960
Width = 1260
End
Begin CommandButton cmdAdd
Caption = "&Add Rec"
Height = 396
Left = 240
TabIndex = 1
Top = 960
Width = 1260
End
Begin TextBox Text1
DataField = "KeyFld"
DataSource = "Data1"
Height = 300
Left = 195
TabIndex = 0
Top = 600
Width = 1260
End
Begin Data Data1
Caption = "Data1"
Connect = ""
DatabaseName = "C:\CODE\IRA\VB\TESTBED\EOF_BOF.MDB"
Exclusive = 0 'False
Height = 300
Left = 192
Options = 0
ReadOnly = 0 'False
RecordSource = "eof_bof"
Top = 192
Width = 5868
End
Begin Label Label1
AutoSize = -1 'True
Caption = "EOF State"
Height = 195
Index = 1
Left = 3240
TabIndex = 10
Top = 600
Width = 855
End
Begin Label Label1
AutoSize = -1 'True
Caption = "BOF State"
Height = 195
Index = 0
Left = 1800
TabIndex = 9
Top = 600
Width = 855
End
End
Option Explicit
Sub cmdAdd_Click ()
'---------------------------------------------
' Notice that the MoveLast is artificial, not
' a true part of the "Add" process. Neither is
' the Find performed after added -- these are
' simply "bells and whistles" I included.
'---------------------------------------------
lstActions.AddItem "Add Record:"
Dim i%
If ((data1.Recordset.EOF = False) Or (data1.Recordset.BOF = False)) Then
data1.Recordset.MoveLast
i% = data1.Recordset.Fields(0)
i% = i% + 1
End If
data1.Recordset.AddNew
text1 = i%
data1.Recordset.Update
' Why do this? To restore position to the latest added record...(!)
data1.Recordset.FindFirst "[KeyFld] = " & i%
End Sub
Sub cmdDelete_Click ()
'---------------------------------------------
' Delete Record (if it exists)
'---------------------------------------------
lstActions.AddItem "Del Record:"
If data1.Recordset.BOF = False And data1.Recordset.EOF = False Then
data1.Recordset.Delete
cmdMove(2).Value = True ' i.e. MoveNext
End If
End Sub
Sub cmdMove_Click (Index As Integer)
'---------------------------------------------
' MoveFirst/Next/Previous/Last code.
' Code to prevent "No Current Record" when
' Move Methods are invoked.
'---------------------------------------------
' Okay, is this an empty table...?
If data1.Recordset.EOF = False And data1.Recordset.BOF = False Then
' No... So let's do a move!
Select Case Index
Case 0 ' MoveFirst
lstActions.AddItem "MoveFirst:"
data1.Recordset.MoveFirst
Case 1 ' MovePrevious
lstActions.AddItem "MovePrevious:"
data1.Recordset.MovePrevious
' Ah, but is there a record there?
If data1.Recordset.BOF = True Then
data1.Refresh
If data1.Recordset.EOF = False Then
data1.Recordset.MoveFirst
End If
End If
Case 2 ' MoveNext
lstActions.AddItem "MoveNext:"
data1.Recordset.MoveNext
' Ah, but is there a record there?
If data1.Recordset.EOF = True Then
data1.Refresh
If data1.Recordset.BOF = False Then
data1.Recordset.MoveLast
End If
End If
Case 3 ' MovePrevious
lstActions.AddItem "MoveLast:"
data1.Recordset.MoveLast
End Select
End If
' Wanna see something irritating? Put the code below in the
' reposition event(!)
If ((data1.Recordset.EOF = True) And (data1.Recordset.BOF = True)) Then
MsgBox "You will probably want to add a record or exit.", 0, "Empty Table!"
End If
End Sub
Sub cmdPrint_Click ()
'------------
' Print List
'------------
Screen.MousePointer = 11
Dim i%
For i% = 0 To lstActions.ListCount - 1
printer.Print lstActions.List(i%)
Next i%
Screen.MousePointer = 0
End Sub
Sub cmdRefresh_Click ()
'---------------------------------------------
' Refresh - Refreshes database
'---------------------------------------------
lstActions.AddItem "Refresh:"
data1.Refresh
End Sub
Sub Data1_Reposition ()
'---------------------------------------------
' Reposition - Just updates the EOF/BOF flags
' and adds to the list.
' Reposition events triggered by the data
' control are rarely a problem (unless the
' table is empty). The Data Control automatically
' prevents moving off the end of a table. It's the
' actual MoveNext/